using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Microblaze.Simulator.Engine;

namespace Weazel.Microblaze.Simulator.Components.Microblaze.Instructions
{
    public class Andni : Instruction
    {
        public override int CycleCount
        {
            get { return 1; }
        }

        public Andni()
            : base("andni")
        {
        }


        /// <summary>
        /// The IMM field is sign-extended to 32 bits. The contents of 
        /// register rA are ANDed with the logical complement of the extended 
        /// IMM field; the result is placed into register rD.
        /// </summary>
        /// <param name="MicroblazeComponent"></param>
        public override void Execute(MicroblazeComponent MicroblazeComponent)
        {
            uint ra = MicroblazeComponent.ReadRegister(SourceRegisterA);
            uint imm = GetImmediateValue(MicroblazeComponent);
            uint nimm = ~imm;
            uint result = ra & nimm;

            MicroblazeComponent.WriteRegister(DestinationRegister, result, Address);
        }

        public override string ToString()
        {
            return String.Format("andni r{0}, r{1}, r{2}",
                DestinationRegister,
                SourceRegisterA,
                SourceRegisterB
            );
        }
    }
}